package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.annotion.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);



    /**
     * 查询菜品是否处于起售状态
     * @param ids
     * @param status
     * @return
     */

    Integer getEnableCount(List<Long> ids, Integer status);

    /*
    //根据id删除dish表
     */
    void deleteById(List<Long> id);

//    /**
//     * 根据id查询菜品分类
//     * @param categoryId
//     * @return
//     */
//    @Select("select * from dish where category_id=#{categoryId}")
//    Dish list(Integer categoryId);

    /**
     * 根据id查询菜品分类
     * @param id
     * @return
     */
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    /**
     * 根据id修改菜品以及口味
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateById(Dish dish);

    /**
     * 菜品起售、停售
     * @param status
     * @param id
     */
    @Update("UPDATE dish SET status=#{status} where id=#{id}")
    void startOrClose(Integer status, Long id);

    /**
     * 根据分类ID查询菜品
     * @param
     * @param categoryId
     * @param name
     * @return
     */
    @Select("SELECT * FROM dish where category_id=#{categoryId} or name like concat('%',#{name},'%')")
    List<Dish> getByCategoryId(Long categoryId, String name);
}
